package com.smartinput.user.query.dao

import com.smartinput.user.query.entry.UserEntry
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.ResultMap

@Mapper
interface UserDao {
    
    // 简单查询使用注解
    @Select("SELECT uid, user_name, email, phone, enabled, created_at, updated_at FROM user WHERE uid = #{uid}")
    @ResultMap("UserEntryMap")
    fun findById(@Param("uid") uid: String): UserEntry?
    
    @Select("SELECT uid, user_name, email, phone, enabled, created_at, updated_at FROM user WHERE user_name = #{userName}")
    @ResultMap("UserEntryMap")
    fun findByUserName(@Param("userName") userName: String): UserEntry?
    
    @Select("SELECT uid, user_name, email, phone, enabled, created_at, updated_at FROM user WHERE email = #{email}")
    @ResultMap("UserEntryMap")
    fun findByEmail(@Param("email") email: String): UserEntry?
    
    @Select("SELECT uid, user_name, email, phone, enabled, created_at, updated_at FROM user WHERE phone = #{phone}")
    @ResultMap("UserEntryMap")
    fun findByPhone(@Param("phone") phone: String): UserEntry?
    
    @Select("SELECT COUNT(*) FROM user")
    fun countAll(): Int
    
    @Select("SELECT COUNT(*) FROM user WHERE enabled = true")
    fun countEnabled(): Int
    
    // 复杂查询使用XML
    /**
     * 查询所有用户
     */
    fun findAll(): List<UserEntry>
    
    /**
     * 分页查询用户
     */
    fun findByPage(@Param("offset") offset: Int, @Param("limit") limit: Int): List<UserEntry>
    
    /**
     * 根据用户名模糊查询
     */
    fun findByUserNameLike(@Param("userName") userName: String): List<UserEntry>
} 